// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
    env: cloud.DYNAMIC_CURRENT_ENV
})

const db = cloud.database();

// 云函数入口函数
exports.main = async (event, context) => {
    const { src, width, height, type } = event
    wx.getImageInfo({
      src: 'src',
    })
    // 写入数据库
    try {
        return await db.collection("Images").add({
            data: {
                src: src,
                width: width,
                height: height,
                type: type,
                create_time: new Date()
            }
        })
    } catch (e) {
        return {
            code: 0,
            message: "catch error !"
        }
    }
    /**
     * db.collection("Images").add({
                    data: {
                        src: ret2.fileID,
                        width: width,
                        height: height,
                        type: type,
                        create_time: new Date()
                    },
                    success: function (res) {
                        console.log("db.", res)
                        return res._id
                    }
                })
     */
    
}